from django.contrib import admin
from blog.models import Post, Tag, Category, Link, UploadFile
from blog.forms import PostAdminForm
import logging


class PostAdmin(admin.ModelAdmin):

    fields = (('title', 'visible'), 'summary', 'content', ('tag', 'category', 'status'))
    list_display = ('title', 'post_tag', 'category', 'publish_datetime', 'update_datetime', 'status',
                    'visible', 'view_count')
    list_editable = ('category', 'status', 'visible')
    date_hierarchy = 'publish_datetime'
    list_per_page = 50
    search_fields = ['title', 'content']
    ordering = ('-publish_datetime',)
    form = PostAdminForm
    filter_horizontal = ('tag', )

    class Media:
        css = {
            "all": ("my_styles.css",)
        }
admin.site.register(Post, PostAdmin)


class TagAdmin(admin.ModelAdmin):
    list_display = ('id', 'content', 'post_count')
    list_editable = ('content',)
    ordering = ('-id',)
admin.site.register(Tag, TagAdmin)


class CategoryAdmin(admin.ModelAdmin):
    list_display = ('id', 'parent', 'enhanced_content', 'post_count')
    list_editable = ('parent',)
    list_display_links = ('enhanced_content', )
    ordering = ('parent', )
admin.site.register(Category, CategoryAdmin)


class LinkAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'url')
#     list_editable = ('name', 'url')
admin.site.register(Link, LinkAdmin)


class UploadFileAdmin(admin.ModelAdmin):
    fields = ('file', 'description')
    list_display = ('file_path', 'description', 'size_human', 'create_datetime', 'url_path')
    search_fields = ['description', 'file_path']
    date_hierarchy = 'create_datetime'
    ordering = ['create_datetime']

admin.site.register(UploadFile, UploadFileAdmin)
